package com.iflytek.day17;

interface Swim1 {
  public abstract void swimming();
}

class Student implements Swim1 {
  @Override
  public void swimming() {
    System.out.println("大学生，混合泳");
  }
}

public class _06_AnonymityInner {
  public static void main(String[] args) {
    // 普通方式传入对象
    // 创建实现类对象
    Student s = new Student();

    goSwimming(s);
    // 匿名内部类使用场景:作为方法参数传递
    Swim1 s3 = new Swim1() {
      @Override
      public void swimming() {
        System.out.println("蝶泳...");
      }
    };
    // 传入匿名内部类
    goSwimming(s3);

    // 完美方案: 一步到位
    goSwimming(new Swim1() {
      public void swimming() {
        System.out.println("大学生, 蛙泳...");
      }
    });

    goSwimming(new Swim1() {
      public void swimming() {
        System.out.println("小学生, 自由泳...");
      }
    });
  }

  // 定义一个方法,模拟请一些人去游泳
  public static void goSwimming(Swim1 s) {
    s.swimming();
  }

}
